package org.example.reentrantlock;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author zhengdp
 * @Description 可重入锁测试--可重入测试
 * @Date 2022/10/30 20:10
 * @Created by zhengdp
 */
@Slf4j(topic = "c.ReentrantLockTest")
public class ReentrantLockTest {
    static ReentrantLock lock = new ReentrantLock();
    public static void main(String[] args) {
        method1();
    }

    public static void method1(){
        lock.lock();
        try{
            log.info("execute method1");
            method2();
        }finally {
            log.info("exit method1");
            lock.unlock();
        }
    }

    public static void method2(){
        lock.lock();
        try{
            log.info("execute method2");
            method3();
        }finally {
            log.info("exit method2");
            lock.unlock();
        }
    }

    public static void method3(){
        lock.lock();
        try{
            log.info("execute method3");
        }finally {
            log.info("exit method3");
            lock.unlock();
        }
    }
}
